
#ifndef _DFA_H_
#define _DFA_H_

#include <iostream.h>
#include <fstream.h>
#include <string.h>

#include <Element.h>
#include <Store.h>
#include <Tokens.h>
#include <Sigma.h>
#include <States.h>
#include <Final.h>
#include <Digraph.h>

typedef enum {
	ipTypeNone, ipTypeSigma, ipTypeStates,
	ipTypeStart, ipTypeDelta, ipTypeFinal
} DfaType;

class DFA {
private :
	Sigma sigma;
	States states;
	Element start;
	Digraph delta;
	Final final;

	char name[256];
	Element currState;
	int valid;

	DfaType check(Element elem);
	Element trace(Element symbol);
	void readFile(char* fname);
	int readTransitions(ifstream& ifs);
	int doTransition(char input);

public :
	DFA();
	DFA(char* fname);

	void read();
	void read(char* fname);
	void reset();
	void run();
	void run(char* input);
	Element state();
	int accepted();

	~DFA();

	friend ostream& operator<<(ostream& os, const DFA& dfa);
};

#endif // _DFA_H_

